<%@page import="models.UserModel"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="models.ConfigModel"%>
<%@page import="models.LinkModel"%>
<%@page import="java.util.ArrayList"%>
<%@page import="org.jsoup.examples.ListLinks"%>

<%
    ArrayList<LinkModel> links = (ArrayList<LinkModel>) request.getAttribute("links");
    ConfigModel siteConfig = (ConfigModel) request.getAttribute("config");
    String image = UrlHelper.getServerUrl(request) + "/blobstore-serve?blob-key=" + siteConfig.getLogo();
    int pages = (Integer) request.getAttribute("page");
    boolean nextPage = (Boolean) request.getAttribute("nextPage");
    boolean prevPage = (Boolean) request.getAttribute("prevPage");
    UserModel user = (UserModel) request.getAttribute("user");
    
%>

<jsp:include page="/layouts/header.jsp">
    <jsp:param name="title" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="description" value="<%=siteConfig.getMetaDescription()%>" />
    <jsp:param name="keywords" value="<%=siteConfig.getMetaKeywords()%>" />
    <jsp:param name="ogsite_name" value="<%=siteConfig.getSiteName()%>" />
    <jsp:param name="ogtitle" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="ogurl" value="<%=UrlHelper.getServerUrl(request)%>" />
    <jsp:param name="ogimage" value="<%=image %>" />
    <jsp:param name="ogdescription" value="<%=siteConfig.getMetaDescription()%>" />
</jsp:include>

		<h2 class="title">Link Directory</h2>
		<div class="dir">
			<a href="/submit-link">Submit Link</a> <> 
			<a href="/submit-category">Submit Category</a>
		</div>
		<br />
		<div class="submit-form list-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form">List Link</div></td>
					</tr>
				</thead>
			    <tbody>
			        <% for (int i = 0; i < links.size(); i++) { %>
			        <tr>
			            <td>
			                <a href="<%=links.get(i).getUrl()%>"><%=links.get(i).getName() %></a>
			                (<a href="/edit-link/<%=links.get(i).getId()%>">Edit</a> - <a href="/delete-link/<%=links.get(i).getId()%>">Delete</a>) <br />
			                <%=links.get(i).getDesc() %>
			                <br />
			                <font color="green"><%=links.get(i).getUrl()%></font>
			            </td>
			        </tr>
			        <% } %>
			    </tbody>
			</table>
			
			<% if (prevPage) { %>
			    <a href="/list-link?page=<%=pages - 1%>">Prev</a>
			<% } %>
			
			<% if (nextPage) { %>
			    <a href="/list-link?page=<%=pages + 1%>">Next</a>
			<% } %>
		</div>


<jsp:include page="/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>